#!/bin/sh

#  If the StartupItems directory has not been created yes, create
#  it and set the owner to root:wheel with the standard 0x755 permissions.

if [ ! -d /Library/StartupItems ] ; then
    sudo mkdir /Library/StartupItems
    sudo chown root:wheel /Library/StartupItems
    sudo chmod 755 /Library/StartupItems
fi

# Create a directory for the startup scripts themselves

if [ ! -d /Library/StartupItems/SATARaid5Daemon ] ; then
    sudo mkdir /Library/StartupItems/SATARaid5Daemon
    sudo chown root:wheel /Library/StartupItems/SATARaid5Daemon
    sudo chmod 755 /Library/StartupItems/SATARaid5Daemon
fi

sudo cp -rpf /Applications/Utilities/Silicon\ Image/SATARaid5/StartupItems/* /Library/StartupItems/SATARaid5Daemon

# Make sure the startup items have the correct permissions
sudo chown root:wheel /Library/StartupItems/SATARaid5Daemon/SATARaid5Daemon
sudo chmod 755 /Library/StartupItems/SATARaid5Daemon/SATARaid5Daemon
sudo chown root:wheel /Library/StartupItems/SATARaid5Daemon/StartupParameters.plist
sudo chmod 644 /Library/StartupItems/SATARaid5Daemon/StartupParameters.plist

#  Now that the daemon has been installed, start it running in the background
ConsoleMessage "GUI postflight Starting SATARaid5Daemon"

/Applications/Utilities/Silicon\ Image/SATARaid5/SATARaid5Daemon &
